/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package foxmob.mlts.view.marker;

import foxmob.mlts.model.MultipleFillInBlankQuestion;
import foxmob.mlts.viewcontroller.marker.MarkAnswerForm;

/**
 *
 * @author Lunayo
 */
public class MarkAnswerSetterPanel extends javax.swing.JPanel {

    /**
     * Creates new form MarkAnswerSetterPanel
     */
    public MarkAnswerSetterPanel() {
        initComponents();
    }
    
    public MarkAnswerSetterPanel(MarkAnswerForm delegate) {
        initComponents();
        this.delegate = delegate;
    }
    
    public void setDelegate(MarkAnswerForm delegate) {
        this.delegate = delegate;
    }
    
    public void setQuestionText(String questionText) {
        this.questionTextLabel.setText(questionText);
    }
    
    public String getQuestionText() {
        return this.questionTextLabel.getText();
    }
    
    public void setQuestionNumber(int number) {
        this.questionNumberLabel.setText("Q" + number + ".");
    }
    
    public void setStudentAnswer(String[] answers) {
        if (answers == null) return;
        String questionText = this.questionTextLabel.getText();
        for (int i = 0; i < answers.length; ++i) {
            questionText = 
                    questionText.replaceFirst("__", "(" + answers[i] + ")");
        }
        this.questionTextLabel.setText(questionText);
        this.repaint();
    }
    
    public void setQuestion(MultipleFillInBlankQuestion question) {
        this.question = question;
    }
    
    public void setStudentAnswerIsCorrect(boolean correctAnswer) {
        if (correctAnswer) {
            this.correctButton.setSelected(true);
            this.wrongButton.setSelected(false);
        } else {
            this.wrongButton.setSelected(true);
            this.correctButton.setSelected(false);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        questionNumberLabel = new javax.swing.JLabel();
        questionTextLabel = new javax.swing.JLabel();
        correctButton = new javax.swing.JToggleButton();
        wrongButton = new javax.swing.JToggleButton();

        questionNumberLabel.setText("Q1.");

        questionTextLabel.setBackground(new java.awt.Color(204, 204, 204));
        questionTextLabel.setText("This is a question!!!!!!!!!!!!!!!!!!!!!!3141324123");
        questionTextLabel.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        questionTextLabel.setVerticalTextPosition(javax.swing.SwingConstants.TOP);

        correctButton.setText("V");
        correctButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                correctButtonActionPerformed(evt);
            }
        });

        wrongButton.setText("X");
        wrongButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                wrongButtonActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(6, 6, 6)
                .add(questionNumberLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(questionTextLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 358, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(correctButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 42, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(1, 1, 1)
                .add(wrongButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 42, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(6, 6, 6)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(questionNumberLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 29, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(correctButton)
                    .add(wrongButton))
                .add(6, 6, 6))
            .add(org.jdesktop.layout.GroupLayout.TRAILING, questionTextLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 29, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void correctButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_correctButtonActionPerformed
        // TODO add your handling code here:
        this.correctButton.setSelected(true);
        this.wrongButton.setSelected(false);
//        try {
//            delegate.correctButtonDidPress(question);
//        } catch (Exception e) {
//            System.err.print("Error : " + e.getMessage());
//        }
    }//GEN-LAST:event_correctButtonActionPerformed

    private void wrongButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_wrongButtonActionPerformed
        // TODO add your handling code here:
        this.correctButton.setSelected(false);
        this.wrongButton.setSelected(true);
//        try {
//            delegate.wrongButtonDidPress(question);
//        } catch (Exception e) {
//            System.err.print("Error : " + e.getMessage());
//        }
    }//GEN-LAST:event_wrongButtonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JToggleButton correctButton;
    private javax.swing.JLabel questionNumberLabel;
    private javax.swing.JLabel questionTextLabel;
    private javax.swing.JToggleButton wrongButton;
    // End of variables declaration//GEN-END:variables

    private MarkAnswerForm delegate;
    private MultipleFillInBlankQuestion question;
}
